package com.tenglong.teacher.ui.adapter.viewholder;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.HomeworkErrerTypeInfo;
import com.tenglong.teacher.ui.adapter.HomeworkErrerDialogAdapter;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

/**
 * @author hdx on 2019/3/21.
 */
public class HomeworkErrerDialogViewHolder extends BaseViewHolder<HomeworkErrerTypeInfo> {
    private TextView tv;
    private HomeworkErrerDialogAdapter.HomeworkErrerDialogListener listener;

    public HomeworkErrerDialogViewHolder(View itemView) {
        super(itemView);
        initView();
    }

    public HomeworkErrerDialogViewHolder(View itemView, HomeworkErrerDialogAdapter.HomeworkErrerDialogListener listener) {
        this(itemView);
        this.listener = listener;
        setListeners();
    }

    private void setListeners() {
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onHomeworkErrerDialogClick(getAdapterPosition());
                }
            }
        });
    }

    private void initView() {
        tv = itemView.findViewById(R.id.tv);
    }

    @Override
    public void setLayoutInfo(HomeworkErrerTypeInfo info) {
        tv.setText(TextUtils.isEmpty(info.wordName) ? "" : info.wordName);
        tv.setSelected(info.isSelected);
    }
}
